package com.yunhe.sms.service.activite.impl;

import com.yunhe.commens.dto.Pagedao;
import com.yunhe.commens.util.DaoFactory;
import com.yunhe.sms.annation.Log;
import com.yunhe.sms.dao.activite.VoteDao;
import com.yunhe.sms.entity.activity.Vote;
import com.yunhe.sms.service.activite.VoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author LeiPeifeng
 * @version V1.0
 * @date 2017/10/30 0030 19:05
 * @Description: 实现接口
 */
@Service
public class VoteServiceImpl implements VoteService{
    @Autowired
    private VoteDao voteDao;
    @Override
    @Log("添加投票")
    public Long add(Vote vote) {
        return voteDao.add ( vote );
    }

    @Override
    @Log("删除投票")
    public void deleted(String ids) {
        if (null != ids && !ids.isEmpty ()){
            String[] split = ids.split ( "," );
            for (String id : split){
                voteDao.deleted ( new Long(id) );
            }
        }
    }

    @Override
    @Log("修改投票")
    public void update(Vote vote) {
        voteDao.update ( vote );
    }

    @Override
    public Vote findId(Long id) {
        return voteDao.findId ( id );
    }

    @Override
    public List<Vote> find() {
        return voteDao.find ();
    }

    @Override
    public Pagedao<Vote> page(int offset, int limit) {
        Pagedao<Vote> pagedao =new Pagedao<> ();
        List<Vote> findpage=null;
        int count = voteDao.count ();//总数
        if (count>0){
            findpage = voteDao.findpage ( offset, limit );//本业数据
            pagedao.setPage ( offset/limit+1 );
            pagedao.setSize ( limit );
        }
        pagedao.setTotal ( count);
        pagedao.setRows ( findpage );
        return pagedao;
    }

    @Override
    public void upstatus(Long id) {
        voteDao.upstatus ( id );
    }
}
